<template>
  <div class="addFeed" :style="'height:' + height + 'px;'">
    <div>
      <HeadTop :title="headTitle"></HeadTop>
      <div class="head-time">{{new Date | format}}</div>
    </div>
    <div class="addClass">
      <div class="addClass-title">生物信息</div>
      <div class="addClass-line"></div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">生物名称</div>
        <div class="addFeed-con-msg">
          <van-dropdown-menu>
            <van-dropdown-item v-model="value" :options="opt" :change="valueChange()" />
          </van-dropdown-menu>
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">计量单位</div>
        <div v-if="opt[value]">
          <input class="addFeed-con-msg" :value="opt[value].measurement" disabled />
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">原库存</div>
        <div v-if="opt[value]">
          <input class="addFeed-con-msg" v-model="opt[value].stock" disabled />
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">现库存</div>
        <div>
          <input class="addFeed-con-msg" v-model="biologyQuantityAfter" />
        </div>
      </div>
    </div>
    <div class="addClass-btn">
      <div class="addClass-btn-hold" @click="submit(0)">保存</div>
      <div class="addClass-btn-submit" @click="submit(1)">提交</div>
    </div>

  </div>
</template>
<script>
  import {
    getBiologyList,
    inertBiology
  } from '../../../../api/index.js'
  import HeadTop from '../../../../components/headTop.vue'
  import {
    getYYYYMMDD
  } from '../../../../api/unit.js'
  export default {
    data() {
      return {
        headTitle: '盘库添加',
        value: 0,
        opt: [],
        height: document.documentElement.clientHeight,
        biologyQuantityAfter: ''

      }
    },
    filters: {
      format: function(value) {
        return getYYYYMMDD(value).nTime
      }
    },
    async mounted() {
      let msg = await getBiologyList()
      let idx = 0
      msg.data.map(v => {
        v.text = v.biologyName
        v.value = idx
        idx++
      })
      this.opt = msg.data

      this.value = msg.data[0].value

       // debugger
    },
    methods: {
      valueChange() {

      },
      async submit(v) {
        if (this.biologyQuantityAfter === '') {
          this.$notify({
            type: 'danger',
            message: '请输入现库存'
          })
          return
        }

        let data = {
          medictionId: this.opt[this.value].id,
          biologyQuantityBefore: this.opt[this.value].stock,
          biologyQuantityAfter: this.biologyQuantityAfter,
          submit: v
        }
        let result = await inertBiology(data)
        if (result.code === 10000) {
          this.$router.go(-1)
        } else {
          this.$notify({
            type: 'danger',
            message: result.msg
          })
        }
      }
    },
    components: {
      HeadTop
    }
  }
</script>

<style scoped>
  .addFeed {
    background: #e5e5e5;
  }

  .head-time {
    width: 750px;
    height: 109px;
    background: #fff;
    border-top: #e5e5e5 2px solid;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    font-weight: bold;
  }

  .addClass {
    background: #fff;
    width: 686px;
    border-top: #e5e5e5 solid 17px;
    padding: 40px 32px;
    font-size: 32px;
    overflow: hidden;
  }

  .addClass-title {
    padding-bottom: 40px;
    font-weight: bold;
    margin-left: 5px;
  }

  .addClass-line {
    background-color: #e5e5e5;
    height: 1px;
    width: 686px;
  }

  .addFeed-con {
    display: flex;
    font-size: 28px;
    color: #757575;
    height: 45px;
    line-height: 45px;
    margin-top: 34px;
  }

  .van-dropdown-menu {
    height: 45px;
    background: #f9f9f8;
    text-align: left;

  }

  .addFeed-con-name {
    width: 150px;
    margin-left: 12px;
  }

  .addFeed-con-msg {
    padding: 0 25px;
    width: 485px;
    background: #f9f9f8;
  }

  .addClass-title-text {
    width: 675px;
    background: #FBF8F9;
    line-height: 54px;
    border: 1px solid #e5e5e5;
  }

  .addClass-btn {
    width: 750px;
    background: #e5e5e5;
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 154px;
    font-size: 32px;
  }

  .addClass-btn-hold {
    width: 332px;
    height: 111px;
    line-height: 111px;
    text-align: center;
    background: #fff;
    font-weight: bold;
    color: #999;
  }

  .addClass-btn-submit {
    width: 332px;
    height: 111px;
    line-height: 111px;
    text-align: center;
    color: #009EEA;
    background: #fff;
    font-weight: bold;
  }
</style>
